#include <stdio.h>
#include <stdlib.h>

int time = 0;
int BLACK = 0;
int GRAY = 1;
int WHITE = 2;

/* typedef struct No No; */

struct No
{
    char chave;
    int color;
    int d;
    struct No* pi;
    int f;
    struct No** adj; /* apontador para apontadores de Nos */
    int len_adj;
};

void BfsVisit(struct No *listaIn[], int posIn)
{
    time = time + 1;

    (*listaIn[posIn]).d = time;
    (*listaIn[posIn]).color = GRAY;

    int count = 0;

    for( ; listaIn[count] != NULL ; count++)
    {
        if((*listaIn[count]).color == WHITE)
        {
            (*listaIn[count]).pi = listaIn[count];
            BfsVisit(listaIn, count);
        }
    }

    (*listaIn[count]).color = BLACK;
    time = time + 1;
    (*listaIn[count]).f = time;
}

void Bfs(struct No *listaIn[])
{
    time = 0;

    int count = 0;

    for( ; listaIn[count] != NULL ; count++)
    {
        if((*listaIn[count]).color == WHITE)
        {
            BfsVisit(listaIn, count);
        }
    }
}

struct No initLista(struct No* listaIn, char* charIn)
{
    listaIn->chave = charIn;
    listaIn->color = WHITE;
    listaIn->d     = -1;
    listaIn->pi    = NULL;
    listaIn->adj   = NULL;
    listaIn->f     = 0;
}

int main()
{
    int time = 0;
    
    struct No* n1;
    n1 = (struct No*) malloc(sizeof(struct No)); 
    
    struct No* n2;
    n2 = (struct No*) malloc(sizeof(struct No)); 
    struct No* n3;
    n3 = (struct No*) malloc(sizeof(struct No)); 
    struct No* n4;
    n4= (struct No*) malloc(sizeof(struct No)); 
    struct No* n5;
    n5 = (struct No*) malloc(sizeof(struct No)); 
    struct No* n6;
    n6 = (struct No*) malloc(sizeof(struct No)); 
    
    initLista(n1, "u");
	initLista(n2, "v");
	initLista(n3, "w");
	initLista(n4, "x");
	initLista(n5, "y");
	initLista(n6, "z");
	
	n1->len_adj = 2;
	n1->adj = (struct No**) malloc(n1->len_adj * sizeof(struct No*));
	n1->adj[0] = n4;
	n1->adj[1] = n2;
	
	/*
    No N1, N2, N3, N4, N5, N6;

    No listaVertice[6] = {N1, N2, N3, N4, N5, N6};

    char listachave[6] = {'u','v','w','x','y','z'};

    int i;

    for(i = 0 ; i <= 6 ; i++)
    {
        initLista(listaVertice[i], listachave[i]);
    }

    listaVertice[0].adj = {N2, N4};
    listaVertice[1].adj = {N5};
    listaVertice[2].adj = {N5, N6};
    listaVertice[3].adj = {N2};
    listaVertice[4].adj = {N4};
    listaVertice[5].adj = {N6};

    Bfs(listaVertice);

    for(int i = 0 ; i <= 6 ; i++)
    {
        printf("%d\n", listaVertice[i].color);
    }
	*/
	free(n1->adj);
	free(n1);
	free(n2);
	free(n3);
	free(n4);
	free(n5);
	free(n6);
	
	
	
    return 0;
}
